package com.totalinlink.dsl.poi.wrappers

import com.totalinlink.dsl.poi.WorkBookBuilder

/**
 * Created by wangguangyu on 15/5/24.
 */
class CellStyleWrapper extends NodeWrapper {

    // name of cell style
    def name
    // workbook wrapper
    def workbook
    // alignment
    def align, verticalAlign
    // border[bottom, top, left, right]
    def border
    // border color
    def borderColor

    // font wrapper
    def font

    @Override
    void syncNode() {

        poiObject = workbook.poiObject.createCellStyle()
        poiObject.alignment = align
        poiObject.verticalAlignment = verticalAlign
        poiObject.borderBottom = border.bottom
        poiObject.borderTop = border.top
        poiObject.borderLeft = border.left
        poiObject.borderRight = border.right

        poiObject.leftBorderColor = borderColor.left
        poiObject.topBorderColor = borderColor.top
        poiObject.rightBorderColor = borderColor.right
        poiObject.bottomBorderColor = borderColor.bottom

        // set font of cell
        poiObject.font = font?.poiObject ?: null

    }

    CellStyleWrapper(WorkBookBuilder workBookBuilder, Map attributes) {
        super(workBookBuilder, attributes)

        workbook = workBookBuilder.workbook
        name = attributes.name
        align = attributes.align
        verticalAlign = attributes.verticalAlign

        border = attributes.border
        borderColor = attributes.borderColor

        font = workbook.namedFonts[attributes.font]

    }

    @Override
    def void setNode(child) {
        return
    }
}
